Introduction
I was looking for a JavaScript banner solution that allows me to run banners on my web, when I discovered the BarelyFitz JavaScript slideshow. It's the best slideshow script I've seen, and I decided to use if for my banners.
Inheritance
The easiest method to "borrow" somebody else's code, is through inheritance. Using Nicholas C. Zakas's technique makes inheritance in JavaScript a dream:
Object.prototype.extend = function (oSuper) {
for (sProperty in oSuper) {
this[sProperty] = oSuper[sProperty];
}
}
function ClassA () {
}
function ClassB() {
this.extend(new ClassA());
}
The Banner Class
The reason I wrote this banner
class, was to be able to have two (or more) banners on one page. The banner
class acts as a wrapper around the slideshow
class and inherits slideshow
's methods and properties.
You'll find a demo here.
Prerequisite
BarelyFitz JavaScript slideshow.js.
The code
<HEAD>
<SCRIPT type="text/javascript" src="slideshow.js"></SCRIPT>
<SCRIPT language="JavaScript1.3" type="text/javascript">
-->
</SCRIPT>
</HEAD>
<BODY onLoad="initBanner();">
<!-- firstBanner.hotlink() is inherited, see "http://www.barelyfitz.com/webapps/apps/slideshow/index.php/5" target=_blank>slideshow documentation -->
<A href="javascript:void(0)" onClick="firstBanner.hotlink();return false;">
<IMG name="BANNER1" src="http://soderlind.no/images/soderlind468x60.gif"
width="468" height="60" border="0">
</A>
<A href="javascript:void(0)" onClick="secondBanner.hotlink();return false;">
<IMG name="BANNER2"
src="http://www.codeproject.com/images/codeproject468x60.gif"
width="468" height="60" border="0">
</A>
</BODY>
Have fun coding.